/**
 * Created by Aber on 17/4/1.
 */
// 加载模块


define('wangEditor',function () {

})
module.exports = function(ngModule) {
    require('./wangEditor.scss');

    ngModule.directive('wangEditor',function () {
        return {
            restrict: 'AE',//元素(element)
            scope: {},
            replace: true,
            require: '?ngModel',
            template: require('./wangEditor.html'),//模板
            controllerAs: 'wangEditor',// <=> $scope.vm = {greeting: '你好，我是卡哥'}
            controller: function () {
            },
            link: function(scope, element, attrs, ngModel) {
                // 初始化 编辑器内容
                if (!ngModel) {
                    return;
                } // do nothing if no ng-model
                // Specify how UI should be updated
                ngModel.$render = function() {
                    element.html(ngModel.$viewValue || '');
                };
                // Listen for change events to enable binding
                element.on('blur keyup change', function() {
                    // scope.$apply(readViewText);
                });
                // No need to initialize, AngularJS will initialize the text based on ng-model attribute
                // Write data to the model
                function readViewText() {
                    var html = element.html();
                    // When we clear the content editable the browser leaves a <br> behind
                    // If strip-br attribute is provided then we strip this out
                    if (attrs.stripBr && html === '<br>') {
                        html = '';
                    }
                    ngModel.$setViewValue(html);
                }
                var wangEditor=require('wangeditor');

                // 创建编辑器
                var editor = new wangEditor(element);
                editor.create();
            }

        }
    });//定义指令，对应页面中的<hello-world></hello-world>

}